package com.lky.mapper;

import com.lky.domain.Planeinformation;
import com.lky.domain.Planetype;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface PlaneinformationMapper {

    //查询全部飞机
    @Select("select * from plane_information")
    @Results(id = "findAllPlaneinformation",value = {
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "type_id",property = "type_id"),
            @Result(column = "type_id",property = "type",
                    one = @One(select = "com.lky.mapper.PlanetypeMapper.findPlanetypeById")),
            @Result(column = "planename",property = "planename"),
            @Result(column = "model",property = "model"),
            @Result(column = "company",property = "company"),
            @Result(column = "year",property = "year"),
            @Result(column = "text",property = "text"),
            @Result(column = "picture",property = "picture")
    })
    List<Planeinformation> findAllPlaneinformation();

    //添加飞机
    @Insert("insert into plane_information(type_id,planename,model,company,year,text,picture) " +
            "values(#{type_id},#{planename},#{model},#{company},#{year},#{text},#{picture})")
    int insertPlaneinformation(Planeinformation planeinformation);

    //根据id查询
    @Select("select * from plane_information where id=#{id}")
    @Results(id = "findPlaneinformationById",value = {
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "type_id",property = "type_id"),
            @Result(column = "type_id",property = "type",
                    one = @One(select = "com.lky.mapper.PlanetypeMapper.findPlanetypeById")),
            @Result(column = "planename",property = "planename"),
            @Result(column = "model",property = "model"),
            @Result(column = "company",property = "company"),
            @Result(column = "year",property = "year"),
            @Result(column = "text",property = "text"),
            @Result(column = "picture",property = "picture")
    })
    Planeinformation findPlaneinformationById(Integer id);
    //更新信息
    @Update("update plane_information " +
            "set type_id=#{type_id},planename=#{planename},model=#{model},company=#{company},year=#{year},text=#{text},picture=#{picture}" +
            "where id=#{id}")
    int updatePlaneinformationById(Planeinformation planeinformation);

    //删除信息
    @Delete("delete from plane_information where id=#{id}")
    int deletePlaneinformationById(Integer id);

    //模糊查询
    @Select("select * from plane_information where 1=1 and planename like CONCAT('%',#{searchParam},'%') " +
            "or model like CONCAT('%',#{searchParam},'%')" +
            "or company like CONCAT('%',#{searchParam},'%')" +
            "or year like CONCAT('%',#{searchParam},'%')" +
            "or text like CONCAT('%',#{searchParam},'%')"+
            "or picture like CONCAT('%',#{searchParam},'%')")
    @Results(id = "findPlaneinformationByStr",value = {
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "type_id",property = "type_id"),
            @Result(column = "type_id",property = "type",
                    one = @One(select = "com.lky.mapper.PlanetypeMapper.findPlanetypeById")),
            @Result(column = "planename",property = "planename"),
            @Result(column = "model",property = "model"),
            @Result(column = "company",property = "company"),
            @Result(column = "year",property = "year"),
            @Result(column = "text",property = "text"),
            @Result(column = "picture",property = "picture")
    })
    List<Planeinformation> findPlaneinformationByStr(String str);

    //根据飞机类型id查询飞机
    @Select("select * from plane_information where type_id=#{type_id}")
    @Results(id = "findPlaneinformationByTypeid",value = {
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "type_id",property = "type_id"),
            @Result(column = "type_id",property = "type",
                    one = @One(select = "com.lky.mapper.PlanetypeMapper.findPlanetypeById")),
            @Result(column = "planename",property = "planename"),
            @Result(column = "model",property = "model"),
            @Result(column = "company",property = "company"),
            @Result(column = "year",property = "year"),
            @Result(column = "text",property = "text"),
            @Result(column = "picture",property = "picture")
    })
    List<Planeinformation> findPlaneinformationByTypeid(Integer id);
}
